Skip to content

Minify and compress schemas in binaries - #6722

Merged
JohnMcPMS merged 8 commits into
microsoft:masterfrom
JohnMcPMS:squish-schemas
Dec 3, 2026
Merged

JohnMcPMS merged 8 commits into
microsoft:masterfrom
JohnMcPMS:squish-schemas

Conversation

@JohnMcPMS

@JohnMcPMS JohnMcPMS commented Dec 1, 2026 •

Copy link
Copy Markdown
Member

📖 Description

Minifies and compresses JSON schemas before including them as resources in our binaries. This saved ~750KiB in local builds.

The compressed resource streams are all created at build time. No additional overhead should be incurred for updating or adding new schemas.

Decompressing the resource streams every time does incur a minor performance penalty. Minification provides an even smaller gain. Together this increases validation times very slightly, depending on the schema being used (at most 10%).

If this becomes an issue (and the winget-pkgs service is the only place I can imagine it would), we should move to caching the parsed schemas at runtime. My investigation into that showed that parsing the schema resources takes 15-20% of the overall validation time. Caching the parsed JSON would then cover both the decompression and parsing. But I suspect even in validation heavy operations the validation itself accounts for a tiny amount of the overall time.

🔍 Validation

New tests are added specifically for compressed resources and the build target.

Microsoft Reviewers: Open in CodeFlow

@JohnMcPMS
JohnMcPMS requested a review from a team as a code owner December 1, 2026 01:34
Copilot AI balanced review requested due to automatic review settings December 1, 2026 01:34
@github-actions

This comment was marked as outdated.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The PowerShell -match operation overwrites the resource match collection in $Matches, causing resource generation to fail and blocking the AppInstallerCLITests build.

1 open issue
What changed in this PR

This PR reduces WinGet’s native binary size by minifying and compressing embedded JSON schemas at build time, then decompressing them when loading schemas for validation.

Changes:

  • Adds a shared build pipeline for JSON minification and MSZIP resource compression.
  • Updates resource and schema loaders to decompress embedded data before parsing.
  • Adds generator tests, native resource tests, documentation, and a release note.
File Description
src/​WinGetSchemas/​WinGetSchemas.vcxitems.filters Classifies package-schema resources as custom-build inputs.
src/​WinGetSchemas/​WinGetSchemas.vcxitems Enables package-schema compression and dependency tracking.
src/​targets/​Test-CompressedResources.ps1 Tests generation, round trips, cleanup, and resource identifiers.
src/​targets/​Generate-CompressedResources.ps1 Generates compressed payloads and rewritten resource scripts.
src/​targets/​CompressedResources.targets Integrates compression, output checks, and cleanup into native builds.
src/​targets/​CompressedResources.md Documents resource compression, usage, and validation.
src/​targets/​CompressedResources.cs Implements compression, decompression, and JSON minification helpers.
src/​ManifestSchema/​ManifestSchema.vcxitems.filters Classifies manifest-schema resources as custom-build inputs.
src/​ManifestSchema/​ManifestSchema.vcxitems Enables manifest-schema compression and dependency tracking.
src/​Directory.Build.targets Imports compression targets for native projects.
src/​AppInstallerSharedLib/​Resources.cpp Implements decompressed resource loading.
src/​AppInstallerSharedLib/​Public/​winget/​Resources.h Declares decompressed resource APIs.
src/​AppInstallerSharedLib/​Public/​winget/​JsonSchemaValidation.h Documents compressed schema loading and adds forward declarations.
src/​AppInstallerSharedLib/​Public/​winget/​Compression.h Declares a pointer-and-size decompression overload.
src/​AppInstallerSharedLib/​JsonSchemaValidation.cpp Decompresses schema resources before parsing.
src/​AppInstallerSharedLib/​Compression.cpp Implements pointer-and-size decompression.
src/​AppInstallerCommonCore/​Manifest/​ManifestSchemaValidation.cpp Routes manifest schemas through the compressed resource loader.
src/​AppInstallerCLITests/​TestData/​CompressedResourceInvalidJson.txt Adds an invalid-JSON fixture.
src/​AppInstallerCLITests/​Resources.cpp Tests binary round trips, schema parity, and loading failures.
src/​AppInstallerCLITests/​CompressedResources.rc Defines compressed-resource test fixtures.
src/​AppInstallerCLITests/​AppInstallerCLITests.vcxproj.filters Registers new test resources in project filters.
src/​AppInstallerCLITests/​AppInstallerCLITests.vcxproj Enables compressed fixtures and original-resource comparisons.
doc/​release-notes/​1.31/​compress-embedded-json-schemas.md Announces smaller native binaries.

Review effort: Balanced

Copilot AI balanced review requested due to automatic review settings December 1, 2026 01:51

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

The pipeline spans MSBuild tracking, RC compilation, and Windows compression APIs, but this review environment could not validate its build lifecycle or native-resource interoperability.

No open issues 🎉

1 resolved since last review

Review effort: Balanced

}
$before = ($records | Measure-Object OriginalBytes -Sum).Sum
$after = ($records | Measure-Object CompressedBytes -Sum).Sum
Write-Host "Packed $($records.Count) resources from '$ResourceScript': $before -> $after bytes."

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Write-Host doesn't work when there is no host and is not able to be suppressed, captured, or redirected reliably in all environments. Write-Information or Write-Output are PowerShell's preferred cmdlets

Also applies to the the Test script

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I read the docs as: Host is for the human, Output is for the pipeline. These are descriptive logging messages, not data for the pipeline to consume later.

Also:

Starting in Windows PowerShell 5.0, Write-Host is a wrapper for Write-Information.

@ranm-msft ranm-msft left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One blocking build issue below.

Copilot AI balanced review requested due to automatic review settings December 1, 2026 19:00

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

Generator tests do not cover the Windows-only MSBuild/RC integration, and clean/incremental builds, deleted-payload recovery, and generator/runtime interoperability could not be validated here.

No open issues 🎉

Review effort: Balanced

Comment thread src/targets/CompressedResources.targets Resolved
Comment thread src/targets/CompressedResources.md Resolved
Comment thread src/targets/CompressedResources.md Resolved
Comment thread src/targets/CompressedResources.md Resolved
Comment thread src/targets/CompressedResources.targets Resolved
}
}

public static string MinifyJson(string input)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would prefer if we did ConvertTo-Json -Compress or used System.Text.Json.JsonSerializer with WriteIndented=false. That may require the script to be PowerShell only and not support Windows PowerShell, but I don't see a reason not to do that.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The custom minifier allows for syntax level validation that the result matches the original. Those other paths require semantic validation, which rely on us having complete coverage over the schema space. While that is something we should strive for, I can't guarantee it. But if we do have it, we can also feel confident in the custom code.

Comment thread src/targets/CompressedResources.cs Resolved
Copilot AI balanced review requested due to automatic review settings December 2, 2026 19:10

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

Native MSBuild rebuild behavior and C#/C++ Cabinet interoperability require Windows integration validation that the stubbed fixtures and review environment could not provide.

No open issues 🎉

Review effort: Balanced

@JohnMcPMS
JohnMcPMS merged commit 05e9d69 into microsoft:master Dec 3, 2026
10 checks passed
@JohnMcPMS
JohnMcPMS deleted the squish-schemas branch December 3, 2026 00:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants